home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
FADER
/
FADE_COD.C
< prev
next >
Wrap
Text File
|
1991-03-01
|
3KB
|
123 lines
/********************************
*
* Fade In! v. 1.0
* by Mark Frohnmayer
*
* This is some code that demonstrates fading. (as per Hypercard dissolve)
* Feel free to use this code in any program of your own - it is public
* domain. If you have any comments or suggestions, code for other fade
* algorithms or bug reports, send them to me at "Mark Frohn" on AOL or
* snail mail me at:
*
* Mark Frohnmayer
* 2875 Baker Blvd.
* Eugene, OR 97403
*
********************************/
GrafPort offScreen;
GrafPtr oldPort;
BitMap offMap[3];
Rect copyRect, bitRect;
Handle fadePats;
int byteWidth;
extern WindowPtr MyWindow;
InitPicts()
{
PicHandle thePic;
int i;
fadePats = GetResource('PAT#', 130);
byteWidth = 44;
SetRect(©Rect, 0, 0, 348, 211);
SetRect(&bitRect, 0, 0, 352, 211);
for(i = 0; i < 3; i++) {
offMap[i].baseAddr = NewPtr((long) (byteWidth * bitRect.bottom));
if(!offMap[i].baseAddr) ExitToShell();
offMap[i].rowBytes = byteWidth;
offMap[i].bounds = bitRect;
}
GetPort(&oldPort);
OpenPort(&offScreen);
offScreen.portRect = bitRect;
offScreen.portBits.bounds = bitRect;
offScreen.portBits.rowBytes = byteWidth;
offScreen.portBits.baseAddr = NewPtr(byteWidth * bitRect.bottom);
if(!offScreen.portBits.baseAddr) ExitToShell();
thePic = GetPicture(128);
EraseRect(&bitRect);
DrawPicture(thePic, ©Rect);
CopyBits(&offScreen.portBits, &offMap[0], ©Rect,
©Rect, srcCopy, 0L);
for(i = 32; i >= 0; i--) {
long curTicks;
curTicks = TickCount();
do {} while(curTicks + 2 > TickCount());
SetFadePat(i);
PaintRect(©Rect);
CopyBits(&offMap[0], &offScreen.portBits, ©Rect,
©Rect, notSrcBic, 0L);
CopyBits(&offScreen.portBits, &MyWindow->portBits, ©Rect,
©Rect, srcCopy, 0L);
}
do{} while(!Button());
for(i = 32; i >= 0; i--) {
long curTicks;
curTicks = TickCount();
do {} while(curTicks + 2 > TickCount());
SetFadePat(i);
PaintRect(©Rect);
CopyBits(&offMap[0], &offScreen.portBits, ©Rect,
©Rect, srcOr, 0L);
CopyBits(&offScreen.portBits, &MyWindow->portBits, ©Rect,
©Rect, srcCopy, 0L);
}
thePic = GetPicture(129);
EraseRect(&bitRect);
DrawPicture(thePic, ©Rect);
CopyBits(&offScreen.portBits, &offMap[0], ©Rect,
©Rect, srcCopy, 0L);
for(i = 0; i < 33; i++) {
long curTicks;
curTicks = TickCount();
do {} while(curTicks + 2 > TickCount());
SetFadePat(i);
PaintRect(©Rect);
CopyBits(&offMap[0], &offScreen.portBits, ©Rect,
©Rect, srcOr, 0L);
CopyBits(&offScreen.portBits, &MyWindow->portBits, ©Rect,
©Rect, srcCopy, 0L);
}
ReleaseResource(thePic);
SetPort(oldPort);
}
UpdatePict()
{
PicHandle thePic;
thePic = GetPicture(129);
DrawPicture(thePic, ©Rect);
ReleaseResource(thePic);
}
SetFadePat(int patNum)
{
GrafPtr oopt;
GetPort(&oopt);
SetPort(&offScreen);
PenPat(*fadePats + 8 * patNum + 2);
SetPort(oopt);
}